/* jshint esversion: 6 */
const Router = require('koa-router');
const tool = require("../../tools/tool");
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
// 修改密码
router.post('/user/recover', async ctx => {
    let id = ctx.request.body.id
    let t = tool.getTime()
    // 先检测是否有客户。有客户先去转移
    let user = await db.models['admin'].findOne({
        where: {
            tenantId: ctx.user.tenantId,
            id: id
        }
    })
    if(!user) return ctx.err('未发现用户,可能已被彻底删除')
    user.isDel = 0
    user.dby = null
    user.dtime = null
    user.uby = ctx.user.id
    user.dtime = tool.getTime()
    await user.save()
    return  ctx.suc('用户已恢复，要登录还需设置密码')
})


module.exports = router;